package LeetCode;

import java.util.Arrays;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName interview
 * @Description: TODO
 * @date ${DAT}14:59
 */
public class LeetCode455 {
    public static void main(String[] args) {
        int[] g = {1,2};
        int[] s = {1,2,3};
        System.out.println(new LeetCode455().findContentChildren(g, s));
    }

    public int findContentChildren(int[] g, int[] s) {
        if (g.length == 0 || s.length == 0){
            return 0;
        }
        Arrays.sort(s);
        Arrays.sort(g);
        int si = s.length - 1;
        int gi = g.length - 1;
        int count = 0;
        while (si >= 0){
            if (s[si] >= g[gi]){
                si--;
                gi--;
                count++;
            }else {
                gi--;
            }
            if (gi < 0) {
                return count;
            }
        }
        return count;
    }
}
